package io.openaev.utils.fixtures.composers;

import io.openaev.database.model.Vulnerability;
import io.openaev.database.repository.VulnerabilityRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class VulnerabilityComposer extends ComposerBase<Vulnerability> {

  @Autowired private VulnerabilityRepository vulnerabilityRepository;

  public class Composer extends InnerComposerBase<Vulnerability> {

    private final Vulnerability vulnerability;

    public Composer(Vulnerability vulnerability) {
      this.vulnerability = vulnerability;
    }

    @Override
    public VulnerabilityComposer.Composer persist() {
      vulnerabilityRepository.save(this.vulnerability);
      return this;
    }

    @Override
    public VulnerabilityComposer.Composer delete() {
      vulnerabilityRepository.delete(this.vulnerability);
      return this;
    }

    @Override
    public Vulnerability get() {
      return this.vulnerability;
    }
  }

  public VulnerabilityComposer.Composer forVulnerability(Vulnerability vulnerability) {
    generatedItems.add(vulnerability);
    return new VulnerabilityComposer.Composer(vulnerability);
  }
}
